#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    while (cin >> n) {
        vector<int> arr(n + 1);
        for (int i = 0; i <= n; i++)
            arr[i]=i;

        while (arr.size() > 1) {
            for (int i = 0; i < arr.size(); i ++) {
                arr.erase(arr.begin() + i);
            }
        }
        cout << arr[0] << endl;
    }
    return 0;
}
